package com.sunsy.authserver.rest;

import com.sunsy.authserver.beans.R;
import com.sunsy.authserver.beans.dto.ForgetPwdDto;
import com.sunsy.authserver.beans.dto.RegisterDto;
import com.sunsy.authserver.beans.dto.UniformUserDTO;
import com.sunsy.authserver.beans.dto.UpdateUserDto;
import com.sunsy.authserver.beans.po.UniformUser;
import com.sunsy.authserver.beans.vo.LoginVo;
import com.sunsy.authserver.service.UniformUserService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequestMapping("user")
public class UserController {

    private UniformUserService userService;

    @Autowired
    public void setUserService(UniformUserService userService) {
        this.userService = userService;
    }

    @ApiOperation(value = "通过code换取用户token")
    @GetMapping("getUserToken")
    public R getUserToken(@RequestParam String code) {
        return R.ok(userService.getUserToken(code));
    }

    @ApiOperation(value = "通过用户token获取用户可见信息")
    @PostMapping("get_info2")
    public R getInfo2(@RequestBody LoginVo vo) {
        return R.ok(userService.getUserInfo2(vo.getUser_token()));
    }

    @ApiOperation("用户注册行为")
    @PostMapping("register")
    public R register(@Valid @RequestBody RegisterDto register) {
        return R.ok(userService.register(register));
    }

    @PutMapping("update")
    public R update(@RequestBody UpdateUserDto userDto){
        return R.ok(userService.userUpdate(userDto));
    }

    @PostMapping("forgetPwd")
    public R forgetPwd(@Valid @RequestBody ForgetPwdDto dto){
        return R.ok(userService.forgetPwd(dto));
    }

}
